var storage = window.localStorage;
function bingWallpaper() {
    $('#bg1').show();
    $('#bg2').hide();
    $.getJSON("/wallpaper.json",
    function(array) {
        // 数据长度
        var length = array.length;
        // 浏览图片索引
        var index = parseInt(storage.imgIndex != null ? storage.imgIndex.split(',') : 0) + 1;
        index = index > length - 1 ? 0 : index;
        // 如果数据包长度变化，显示最新的图片
        var dataLen = storage.dataLen != null ? storage.dataLen.split(',') : 0;
        if (dataLen != length) {
            index = length - 1;
            storage.dataLen = [length];
        }
        // 记录索引
        storage.imgIndex = [index];
        // 根据索引获取图片对象
        var img = array[storage.imgIndex];
        // 拼接图片URL
        var imgUrl = 'url(/wallpaper/' + img.folderName + "/" + img.fileName + ".jpeg";
        $("#title").html("Bing壁纸 - " + img.copyright);
        // 显示图片
        $('#bg2').css('background-image', imgUrl);
        $("#bg1").fadeOut(1200,function() {
            $('#bg1').css('background-image', imgUrl)
        });
        $("#bg2").fadeIn(1200);
        // 风车旋转延迟
        setTimeout(function(){
            while ((win = winTimer.pop()) != undefined) {
                clearInterval(win)
            }
        },
        1200);
    });
    $.getJSON("https://v1.hitokoto.cn/?encode=json", function(a) {
        $("#hitokoto").html(a.from + "：" + a.hitokoto);
    });
}
bingWallpaper();
var winTimer = new Array();
var angle = storage.angle ? storage.angle: 360;
$('.winnower img').css('transform', 'rotate(' + angle + 'deg)');
$('.winnower').click(function() {
    if (winTimer.length > 0) return;
    bingWallpaper();
    winTimer.push(setInterval(function() {
        winTimer.push(setInterval(function() {
            $('.winnower img').css('transform', 'rotate(' + angle + 'deg)');
            angle = angle - 0.00123456789;
            if (angle < 0) {
                angle = 360
            }
            storage.angle = [angle]
        },
        1))
    }, 1))
}); 
(function(a, h, g, f, e, d, c, b) {
    b = function() {
        d = h.createElement(g);
        c = h.getElementsByTagName(g)[0];
        d.src = e;
        d.charset = "utf-8";
        d.async = 1;
        c.parentNode.insertBefore(d, c)
    };
    a["SeniverseWeatherWidgetObject"] = f;
    a[f] || (a[f] = function() { (a[f].q = a[f].q || []).push(arguments)
    });
    a[f].l = +new Date();
    if (a.attachEvent) {
        a.attachEvent("onload", b)
    } else {
        a.addEventListener("load", b, false)
    }
} (window, document, "script", "SeniverseWeatherWidget", "//cdn.sencdn.com/widget2/static/js/bundle.js?t=" + parseInt((new Date().getTime() / 100000000).toString(), 10)));
window.SeniverseWeatherWidget('show', {
    flavor: "bubble",
    location: "WX4FBXXFKE4F",
    geolocation: true,
    language: "auto",
    unit: "c",
    theme: "auto",
    token: "e14489a8-9a7e-477d-9c6c-b4b390175cca",
    hover: "enabled",
    container: "tp-weather-widget"
});